<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui"
	template="/templates/template.xhtml" xmlns:eq="http://www.equus.com.br/facelets/">

	<f:metadata>
		<f:event type="preRenderView" listener="#{medicaoAnimalBean.verificarAcesso}" />
	</f:metadata>

	<ui:define name="body">
		<h:form id="form" prependId="false">
			<h:panelGrid id="tagOs" width="100%">
				<eq:animal animal="#{medicaoAnimalBean.animal}" />
			</h:panelGrid>
			<p:fieldset legend="#{medicaoAnimalBean.qualifiedName}" id="fieldPrincipal">
				<p:tab title="Mediçao do Animal" id="tabMedicao">
					<h:panelGrid columns="4" id="panelMedicao" columnClasses="coluna15,coluna40,coluna20,coluna35" width="100%">

						<h:outputLabel value="Parte de Medição:" styleClass="icoObrigatorio" />
						<p:selectOneMenu id="idParte" effect="fade" style="width:300px;" value="#{medicaoAnimalBean.idParteMedicao}"
							requiredMessage="#{medicaoAnimalBean.requiredMessage}" required="true">
							<f:selectItem itemLabel="Selecione" itemValue="" />
							<f:selectItems value="#{medicaoAnimalBean.listaParteMedicao}" />
						</p:selectOneMenu>
						<p:message for="idParte" />
						<h:outputText value=" " />

						<h:outputLabel value="Unidade de medida:" styleClass="icoObrigatorio" />
						<p:selectOneMenu id="idUnidadeMedida" effect="fade" style="width:300px;" value="#{medicaoAnimalBean.idTipoMedida}"
							requiredMessage="#{medicaoAnimalBean.requiredMessage}" required="true">
							<f:selectItem itemLabel="Selecione" itemValue="" />
							<f:selectItems value="#{medicaoAnimalBean.listaTipoMedida}" />
						</p:selectOneMenu>
						<p:message for="idUnidadeMedida" />
						<h:outputText value=" " />


						<h:outputLabel value="Medida:" styleClass="icoObrigatorio" />
						<p:inputText value="#{medicaoAnimalBean.model.valorToString}" id="valorMedicao" size="20" maxlength="7"
							requiredMessage="#{medicaoAnimalBean.requiredMessage}" required="true" />
						<p:message for="valorMedicao" />
						<h:outputText value=" " />

						<h:outputLabel value="Observação:" />
						<p:inputTextarea autoResize="false" value="#{medicaoAnimalBean.model.observacao}" id="obsMedicao" cols="50"
							rows="5" />
				 </h:panelGrid>
					<br />
					<p:toolbar>
						<p:toolbarGroup align="left">
							<p:commandButton value="Voltar" immediate="true" ajax="false" action="pesquisarAnimal.jsf" />
							<p:commandButton value="Limpar" immediate="true" ajax="false" action="#{medicaoAnimalBean.limparTela}" />
							<p:commandButton rendered="#{p:ifGranted('ROLE_MEDICAO_SALVAR')}" value="Salvar" ajax="true" process="@form"
								update="@form" action="#{medicaoAnimalBean.save}" />
						</p:toolbarGroup>
					</p:toolbar>
					<br />
					<p:dataTable var="medicao" id="listaMedicao" emptyMessage="#{medicaoAnimalBean.emptyMessage}" update="listaMedicao"
						rowsPerPageTemplate="#{medicaoAnimalBean.paginacao}" styleClass="coluna100"
						value="#{medicaoAnimalBean.lazyDataModel}" paginator="true" rows="5"
						rowStyleClass="#{empty rowIx or rowIx mod 2 ne 0 ? 'linhaImpar' : 'linhaPar'}" rowIndexVar="rowIx">

						<p:column headerText="Parte de Medição" filterBy="#{medicao.parteMedicao.descricao}"
							sortBy="#{medicao.parteMedicao.descricao}" style="width:30%">
							<h:outputLabel value="#{medicao.parteMedicao.descricao}" />
						</p:column>
						<p:column headerText="Unidade de medida" filterBy="#{medicao.unidadeMedida.descricao}"
							sortBy="#{medicao.unidadeMedida.descricao}" style="width:20%">
							<h:outputLabel value="#{medicao.unidadeMedida.descricao}" />
						</p:column>
						
						<p:column headerText="Medida" sortBy="#{medicao.valor}" style="width:15%">
							<h:outputLabel value="#{medicao.valor}" />
						</p:column>
						<p:column headerText="Data Cadastro" sortBy="#{medicao.dtCadastro}" style="width:15%">
							<h:outputLabel value="#{medicao.dtCadastro}">
								<f:convertDateTime pattern="dd/MM/yyyy" />
							</h:outputLabel>
						</p:column>

						<p:column headerText="Ações" style="width:10%;text-align:center;">

							<p:commandLink rendered="#{p:ifGranted('ROLE_MEDICAO_EDITAR')}" title="Editar" style="padding:5px !important;"
								update=":form:panelMedicao" process="@this" action="#{medicaoAnimalBean.load}">
								<h:graphicImage library="design/imagem" name="icone-editar.png" />
								<f:setPropertyActionListener target="#{medicaoAnimalBean.model}" value="#{medicao}" />
							</p:commandLink>

							<p:commandLink rendered="#{p:ifGranted('ROLE_MEDICAO_EXCLUIR')}" title="Excluir" process="@this"
								oncomplete="confirmationMedicao.show()">
								<h:graphicImage library="design/imagem" name="icone-excluir.png" />
								<f:setPropertyActionListener target="#{medicaoAnimalBean.model}" value="#{medicao}" />
							</p:commandLink>
						</p:column>
					</p:dataTable>
					<p:confirmDialog appendToBody="true" message="Confirma a Exclusão" header="Exclusão" severity="alert"
						widgetVar="confirmationMedicao">
						<h:panelGrid columns="2">
							<p:commandButton value="Sim" update="listaMedicao" oncomplete="confirmationMedicao.hide()"
								actionListener="#{medicaoAnimalBean.delete}" immediate="true" />
							<p:commandButton value="Não" onclick="confirmationMedicao.hide()" />
						</h:panelGrid>
					</p:confirmDialog>

				</p:tab>
			</p:fieldset>
		</h:form>
	</ui:define>
</ui:composition>